package com.jiuyun.servlet;

//�Զ���servlet����
import java.io.IOException;
import java.lang.reflect.Method;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaseServlet extends HttpServlet {

    public void hello(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("找不到此方法.....");
    }

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //    你访问/user/find
        String url = request.getRequestURI();
        // 查找指定字符最后一次出现的位置
        int gang = url.lastIndexOf("/");
        // 截取指定字符
        String work = url.substring(gang+1);
        System.out.println(url + "你在干嘛" + work);

        // 方法
        Method m = null;
        try {
            m =this.getClass().getDeclaredMethod(work, HttpServletRequest.class,HttpServletResponse.class);
            //调用
            m.invoke(this, request,response);
        }  catch (Exception e) {
            this.hello(request, response);
        }
    }
}



